package asteroids.components;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Circle;

public class Bullet extends AbstractAsteroidsGameComponent {
	
	private int diameter = 4;
	
	public Bullet() {}

	public void shoot(double x, double y, SpaceShip ship) {
		this.setX(x);
		this.setY(y);
		this.setSpeed(ship.getSpeed() + 5);
		this.setVersorI(ship.getVersorI());
		this.setVersorJ(ship.getVersorJ());
		this.setAppearance(new Circle(Color.RED, this.getDiameter()));
	}

	@Override
	public void update(DeltaState deltaState) {
		this.move(-this.getSpeed() * this.getVersorI(), -this.getSpeed() * this.getVersorJ());
		
		if (this.getY() > this.getGame().getDisplayHeight() || this.getX() > this.getGame().getDisplayWidth() ||
				this.getY() + this.getAppearance().getHeight() < 0 || this.getX() + this.getAppearance().getWidth() < 0)
			this.getScene().removeBulletFromGame(this);
		
		this.getScene().updateBulletHitAsteroid(this);
	}
	
	public void takeBackToTheGame() {
		this.setDestroyPending(false);
	}
	
	
	
	

	public int getDiameter() {
		return diameter;
	}
}
